package com.cloud.bc.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.model.entity.*;
import com.cloud.bc.model.enums.PhotoEnum;
import com.cloud.bc.service.*;
import com.cloud.bc.util.OrderNoUtil;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("m/center")
@AllArgsConstructor
public class MCenterController extends BaseController {
    private final BcUsersService bcUsersService;
    private final BcSinglesService bcSinglesService;
    private final BcUserPhotosService bcUserPhotosService;
    private final BcSingleContactsService bcSingleContactsService;
    /**
     * 用户中心
     */
    @GetMapping("")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request,"个人中心", "m/center/index");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcSingles bcSingles = bcSinglesService.selectOne(new BcSingles().setUserId(userInfo.getId()));
        if (StrUtil.isEmpty(bcSingles.getPhoto())) {
            bcSingles.setPhoto("/m/img/avatar_default.png");
        } else {
            bcSingles.setPhoto(bcSingles.getPhoto() + "_200x200.jpg");
        }
        view.addObject("pop", bcSingleContactsService.getCenterPop(request, response, userInfo.getId()));
        view.addObject("userinfo", bcSingles);
        BcSingleContacts bcSingleContacts = bcSingleContactsService.selectOne(new BcSingleContacts().setUserId(userInfo.getId()));
        view.addObject("bcSingleContacts", bcSingleContacts);
        return view;
    }


    /**
     * 上传照片
     */
    @GetMapping("singlephoto")
    public ModelAndView singlephoto(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request,"上传照片", "m/singlephoto");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcSingles bcSingles = bcSinglesService.selectOne(new BcSingles().setUserId(userInfo.getId()));
        view.addObject("bcSingles", bcSingles);
        return view;
    }


    /**
     * 修改手机号
     */
    @GetMapping("usermobile")
    public ModelAndView usermobile(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request,"修改手机号", "m/center/usermobile");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        BcSingles bcSingles = bcSinglesService.selectOne(new BcSingles().setUserId(userInfo.getId()));
        view.addObject("bcSingles", bcSingles);
        return view;
    }



}
